package com.example.swordjava;


public class Test28 {

    public static void main(String[] args) {

        int[] a = {2, 3, 1, 0, 2, 5, 3};
    }

    class TreeNode {
        TreeNode left = null;
        TreeNode right = null;
        int val;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    /**
     * 给定一棵二叉树，判断其是否是自身的镜像（即：是否对称）
     */

    public boolean isSymmetrical(Test29.TreeNode pRoot) {
        // write code here
        if (pRoot == null) return true;
        return isSame(pRoot.left, pRoot.right);
    }

    private boolean isSame(Test29.TreeNode left, Test29.TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        if (left.val == right.val) {
            return isSame(left.left, right.right) && isSame(left.right, right.left);
        } else {
            return false;
        }
    }




}
